package carpediem.xin.tamplate.application;

import android.app.Application;
import android.content.res.Resources;

import java.lang.ref.WeakReference;

import carpediem.xin.tamplate.BuildConfig;
import carpediem.xin.tamplate.util.logger.CrashReportingTree;
import timber.log.Timber;

/**
 * Created by zhaijianwei on 17/2/23.
 * 1.提供全局单例
 */
public class CustomApplication extends Application {
    private static WeakReference<CustomApplication> _instance;

    /*Begin for 公共接口 */
    public static CustomApplication getContext() {
        if (null == _instance) {
            return null;
        }
        return _instance.get();
    }

    public static Resources Resources() {
        return getContext().getResources();
    }
    /*End for 公共接口 */

    @Override
    public void onCreate() {
        super.onCreate();
        //全局单例
        this._instance = new WeakReference<CustomApplication>(this);
        //日志
        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
        } else {
            Timber.plant(new CrashReportingTree());
        }
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

}
